package com.example.ui.leftmenu;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.os.Message;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.inputmethod.InputMethodManager;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.TextView.BufferType;

import com.example.entity.BlogPic;
import com.example.entity.ShareEntity;
import com.example.huashangapp.BaseView;
import com.example.huashangapp.HSApplication;
import com.example.huashangapp.R;
import com.example.net.Communication;
import com.example.service.MainService;
import com.example.ui.contact.face.CirclePageIndicator;
import com.example.ui.contact.face.FaceAdapter;
import com.example.ui.contact.face.FacePageAdeapter;
import com.example.ui.contact.face.FaceUtil;
import com.example.ui.contact.face.FaceViewPager;
import com.example.ui.contact.face.FaceViewPager.TransitionEffect;
import com.example.ui.homepage.HomePageView;
import com.example.ui.leftmenu.Item05View.MyListViewAdapter.ViewHolder;
import com.example.ui.share.AlbumActivity;
import com.example.ui.share.CircleGroupActivity;
import com.example.ui.share.PublishShareActivity;
import com.example.ui.share.ShareContentActivity;
import com.example.util.BitmapLoad;
import com.example.util.PullDownView;
import com.example.util.PullDownView.OnPullDownListener;
import com.example.util.Util;

public class Item05View extends BaseView implements OnPullDownListener{

	private Context mContext;
	public static List<ShareEntity> moreShareList;

	public static final int FAIL = 0;
	public static final int SUCCESS = 1;
	public static final int ADD_PRAISE_SUCCESS = 2;
	public static final int ADD_COMMENTE_SUCCESS = 3;
	public static final int GET_MORE_NEW_SHARE = 4;
	public static final int REFERSH = 5;
//	public static final int MORE = 6;
	
	//加载时 相关控件
	private LinearLayout loadLayout;
	private ProgressBar loadProgressBar;
	private ImageView loadImg;
	
	//正文内容相关控件
	private Button titleLeftBtn,titleRightBtn;
	private TextView titleText;
	private PullDownView mPullDownView;
	public static ListView listview;
	public static MyListViewAdapter listAdapter;
	
	//底部相关控件
	private RelativeLayout bottomLayout1,bottomLayout2;
	private Button bottomPublishCommentBtn,commentBtn;
	private ImageView bottomLeftPhontBtn,bottomRightCameraBtn,faceImg;
	private EditText contentEdit;
//	private View footView;
//	private Button footMoreBtn;
//	private LinearLayout footLoadMoreLayout;
	
	//相关数据
	ViewHolder holder = null;
	
	public static Handler handler;
	private int listCount = 0;
	long dataTime;
	private String time;
	private int typeID;
	private String toUserId,toBlogId;
	@SuppressLint("SimpleDateFormat")
	private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
	String[] imgPath = null;
	List<String> picList;
	List<BlogPic> blogImg;
	
	private View addLikeView;//赞
	private View addCommentView;//评论
	private int likePosition;//赞的位置记录
	Integer addCommentCount;
	HSApplication hsApplication;
	//表情控件
	private FaceUtil faceUtil = HSApplication.getInstance().getFaceUtil();
	private LinearLayout faceLinearLayout;
	private FaceViewPager faceViewPager;
	private boolean isFaceShow = false;
	private InputMethodManager imm;
	private List<String> keys;
	private int currentPage = 0;
	private String headPath;
		
	public Item05View(Context context, HSApplication hsApplication){
		mContext = context;
		this.hsApplication=hsApplication;
	}
	
	
	@SuppressLint("HandlerLeak")
	public void init(){
		imm = (InputMethodManager)mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
		view = LayoutInflater.from(mContext).inflate(R.layout.item05, null);
//		footView = LayoutInflater.from(mContext).inflate(R.layout.homepage_footer,null);
		headPath=HSApplication.sp.getString("imgHead","").toString();
		findView();
		
		titleClick();
	   
		listView();
		
		bottomClick();
		
		initFacePage();//表情控件
		
		handler = new Handler(){
			@Override
			public void handleMessage(Message msg) {
				switch (msg.what) {
				case FAIL:
					Util.toast(mContext, "网络连接有误");
					loadProgressBar.setVisibility(View.GONE);
					loadImg.setVisibility(View.VISIBLE);
					break;
				case SUCCESS:
					loadLayout.setVisibility(View.GONE);
					listAdapter = new MyListViewAdapter();
					listview.setAdapter(listAdapter);
					// 告诉它数据加载完毕;
                    mPullDownView.notifyDidLoad();
					mPullDownView.enableAutoFetchMore(true, 2);
					
					break;
				case ADD_PRAISE_SUCCESS://增加赞成功
					loadLayout.setVisibility(View.GONE);

					String likeCountStr = ((TextView) addLikeView).getText().toString();
					Integer likeCount = Integer.valueOf(likeCountStr);
					likeCount++;
					((TextView)addLikeView).setText(likeCount+"");

					MainService.newShareEntity.get(likePosition).setPraised(true);
//					listAdapter.notifyDataSetChanged();
					break;
				case ADD_COMMENTE_SUCCESS://增加评论成功
					loadLayout.setVisibility(View.GONE);
					bottomLayout1.setVisibility(View.VISIBLE);
					bottomLayout2.setVisibility(View.GONE);
					Util.toast(mContext, "评论成功");
					
					((TextView)addCommentView).setText(addCommentCount+"");
					
					break;
				case GET_MORE_NEW_SHARE:
					List<ShareEntity> updateListData = moreShareList;
					 if(updateListData.size()!=0){
						 for(ShareEntity share:updateListData){
							 MainService.newShareEntity.add(share);
						 }
						 listAdapter.count+=updateListData.size();
						 listAdapter.notifyDataSetChanged();
//							footMoreBtn.setVisibility(View.VISIBLE);
//							footLoadMoreLayout.setVisibility(View.GONE);
							
					 }else{
						 //listview.removeFooterView(footView);
						 Util.toast(mContext, "数据加载完毕");
						 mPullDownView.removeMoreView();
					 }
					 // 告诉它获取更多完毕
					 mPullDownView.notifyDidMore();
					break;
				case REFERSH:
					loadLayout.setVisibility(View.GONE);
					listAdapter = new MyListViewAdapter();
					listview.setAdapter(listAdapter);
					mPullDownView.enableAutoFetchMore(true, 1);
					listAdapter.notifyDataSetChanged();
					// 告诉它更新完毕
                    mPullDownView.notifyDidRefresh();
					break;

				default:
					break;
				}
				
				super.handleMessage(msg);
			}
		};
		
	}
	
	private void findView() {
		titleLeftBtn = (Button)view.findViewById(R.id.layout_title_left_btn);
		titleRightBtn= (Button) view.findViewById(R.id.layout_title_right_btn);
		titleText=(TextView)view.findViewById(R.id.layout_title_middle_text);
		mPullDownView = (PullDownView)view.findViewById(R.id.item05_listview);
		
		loadLayout=(LinearLayout)view.findViewById(R.id.load_layout);
		loadProgressBar=(ProgressBar)view.findViewById(R.id.load_progressbar);
		loadImg = (ImageView)view.findViewById(R.id.load_logo_img);
		
		bottomLayout1=(RelativeLayout)view.findViewById(R.id.item05_bottom_layout1);
		bottomLeftPhontBtn=(ImageView)view.findViewById(R.id.layout_bottom_photo_album);
		bottomPublishCommentBtn=(Button)view.findViewById(R.id.layout_bottom_publish_comment_edit);
		bottomRightCameraBtn=(ImageView)view.findViewById(R.id.layout_bottom_camera);
		bottomLayout2=(RelativeLayout)view.findViewById(R.id.item05_bottom_layout2);
		faceImg=(ImageView)view.findViewById(R.id.share_content_bottom_face);
		contentEdit=(EditText)view.findViewById(R.id.share_content_bottom_comment_edit);
		commentBtn=(Button)view.findViewById(R.id.share_content_bottom_recommend_btn);
		faceLinearLayout = (LinearLayout)view.findViewById(R.id.face_ll);
		faceViewPager = (FaceViewPager)view.findViewById(R.id.face_pager);
//		footMoreBtn=(Button)footView.findViewById(R.id.footer_more_btn);
//		footLoadMoreLayout=(LinearLayout)footView.findViewById(R.id.foot_load_more_layout);
		
		initView();
	}

	private void initView() {
		titleLeftBtn.setText("菜单");
		titleText.setText("最新分享");
		titleRightBtn.setText("圈子");
		Drawable drawable = mContext.getResources().getDrawable(R.drawable.qztb);
		drawable.setBounds(0, 0, 20, 20);
		titleRightBtn.setCompoundDrawables(null, null, drawable, null);

		mPullDownView.setOnPullDownListener(this);
		listview = mPullDownView.getListView();
        
	}



	private void titleClick() {
		titleLeftBtn.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				myMoveView.showHideLeftMenu();
				if(MainService.isLeftMenu==true){
					listview.setEnabled(false);
					bottomLeftPhontBtn.setClickable(false);
				}else{
					listview.setEnabled(true);
					bottomLeftPhontBtn.setClickable(true);
				}
				
			}
		});
		titleRightBtn.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				mContext.startActivity(new Intent(mContext, CircleGroupActivity.class));
			}
		});
		
	}

	/**
	 * 发表分享
	 */	
	private void bottomClick() {
		bottomLeftPhontBtn.setOnClickListener(new OnClickListener() {//相册
			
			@Override
			public void onClick(View v) {
				Intent albumIntent = new Intent(mContext, AlbumActivity.class);
//				albumIntent.putExtra("myHead", HomePageView.headPath);
//				albumIntent.putExtra("type", "album");
				mContext.startActivity(albumIntent);
			}
		});
		
		bottomPublishCommentBtn.setOnClickListener(new OnClickListener() {
			
			

			@Override
			public void onClick(View v) {
				Intent publishIntent = new Intent(mContext, PublishShareActivity.class);
				publishIntent.putExtra("myHead", headPath);
				publishIntent.putExtra("type", "edit");
				mContext.startActivity(publishIntent);
			}
		});
		bottomRightCameraBtn.setOnClickListener(new OnClickListener() {//拍照
	
			@Override
			public void onClick(View v) {
				Intent cameraIntent = new Intent(mContext, PublishShareActivity.class);
				cameraIntent.putExtra("myHead", headPath);
				cameraIntent.putExtra("type", "camera");
				mContext.startActivity(cameraIntent);
				
			}
		});
		
		faceImg.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				if (!isFaceShow) {
					imm.hideSoftInputFromWindow(contentEdit.getWindowToken(), 0);
					try {
						Thread.sleep(80);// 解决此时会黑一下屏幕的问题
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
					faceLinearLayout.setVisibility(View.VISIBLE);
					isFaceShow = true;
				} else {
					faceLinearLayout.setVisibility(View.GONE);
					isFaceShow = false;
				}
			}
		});
		commentBtn.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				String commentContent = contentEdit.getText().toString().trim().toString();
				if("".equals(commentContent)){
					Util.toast(mContext, "请输入内容");
				}else{
					Communication.addComment(HSApplication.sp.getString("userid","").toString(),toUserId,toBlogId,commentContent,"0","item05");
					
					
				}

			}
		});
		
	}
	
	/**
	 * 表情
	 */
	private void initFacePage() {
		Set<String> keySet = HSApplication.getInstance().getFaceMap()
				.keySet();
		keys = new ArrayList<String>();
		keys.addAll(keySet);
		
		List<View> lv = new ArrayList<View>();
		for (int i = 0; i < HSApplication.NUM_PAGE; ++i)
			lv.add(getGridView(i));
		FacePageAdeapter adapter = new FacePageAdeapter(lv, faceViewPager);
		faceViewPager.setAdapter(adapter);
		faceViewPager.setCurrentItem(currentPage);
		faceViewPager.setTransitionEffect(TransitionEffect.CubeOut);
		CirclePageIndicator indicator = (CirclePageIndicator)view.findViewById(R.id.indicator);
		indicator.setViewPager(faceViewPager);		
		adapter.notifyDataSetChanged();
		faceLinearLayout.setVisibility(View.GONE);
		indicator.setOnPageChangeListener(new OnPageChangeListener() {

			@Override
			public void onPageSelected(int arg0) {
				currentPage = arg0;
			}

			@Override
			public void onPageScrolled(int arg0, float arg1, int arg2) {
				// do nothing
			}

			@Override
			public void onPageScrollStateChanged(int arg0) {
				// do nothing
			}
		});
		adapter.notifyDataSetChanged();
		//faceLinearLayout.setVisibility(View.GONE);
		


	}
	
	private GridView getGridView(int i) {
		GridView gv = new GridView(mContext);
		gv.setNumColumns(7);
		gv.setSelector(new ColorDrawable(Color.TRANSPARENT));// 屏蔽GridView默认点击效果
		gv.setBackgroundColor(Color.TRANSPARENT);
		gv.setCacheColorHint(Color.TRANSPARENT);
		gv.setHorizontalSpacing(1);
		gv.setVerticalSpacing(1);
		gv.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
				LayoutParams.MATCH_PARENT));
		gv.setGravity(Gravity.CENTER);
		gv.setAdapter(new FaceAdapter(mContext, i));
		gv.setOnTouchListener(forbidenScroll());
		gv.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				if (arg2 == HSApplication.NUM) {// 删除键的位置
					int selection = contentEdit.getSelectionStart();
					String text = contentEdit.getText().toString();
					if (selection > 0) {
						String text2 = text.substring(selection - 1);
						if ("]".equals(text2)) {
							int start = text.lastIndexOf("[");
							int end = selection;
							contentEdit.getText().delete(start, end);
							return;
						}
						contentEdit.getText().delete(selection - 1, selection);
					}
				} else {
					int count = currentPage * HSApplication.NUM + arg2;

					String ori = contentEdit.getText().toString();
					int index = contentEdit.getSelectionStart();
					StringBuilder stringBuilder = new StringBuilder(ori);
					stringBuilder.insert(index, keys.get(count));
					contentEdit.setText(stringBuilder.toString());
					contentEdit.setSelection(index + keys.get(count).length());
				}
			}
		});
		return gv;
	}
	
	// 防止乱pageview乱滚动
	private OnTouchListener forbidenScroll() {
		return new OnTouchListener() {
			@Override
			public boolean onTouch(View v, MotionEvent event) {
				if (event.getAction() == MotionEvent.ACTION_MOVE) {
					return true;
				}
				return false;
			}

		};
	}	
	
	private void listView() {
		//listview.addFooterView(footView);
		Communication.getNewShare(listCount,"load");//第一次查询为0
		listview.setOnScrollListener(new OnScrollListener() {
			
			@Override
			public void onScrollStateChanged(AbsListView view, int scrollState) {
				// TODO Auto-generated method stub
				if(bottomLayout2.getVisibility()==View.VISIBLE){
					bottomLayout2.setVisibility(View.GONE);
					bottomLayout1.setVisibility(View.VISIBLE);
					
					imm.hideSoftInputFromWindow(contentEdit.getWindowToken(), 0);
					faceLinearLayout.setVisibility(View.GONE);
					isFaceShow = false;	
				}
			}
			
			@Override
			public void onScroll(AbsListView view, int firstVisibleItem,
					int visibleItemCount, int totalItemCount) {
				// TODO Auto-generated method stub
				
			}
		});
		listview.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int position,
					long arg3) {
				
				holder.like_count.setFocusable(false);
				holder.comment_count.setFocusable(false);
				holder.like_count.setEnabled(false);
				holder.comment_count.setEnabled(false);
				
				Intent intent = new Intent(mContext, ShareContentActivity.class);
				intent.putExtra("myId", MainService.newShareEntity.get(position).getUid()+"");
				intent.putExtra("shareId", MainService.newShareEntity.get(position).getId()+"");//分享的id
				intent.putExtra("type", MainService.newShareEntity.get(position).getTypeId());//内容种类
				intent.putExtra("headImg", MainService.newShareEntity.get(position).getHeadPic());//头像
				intent.putExtra("name", MainService.newShareEntity.get(position).getNickname());//姓名
//				intent.putExtra("time", time);//时间
				intent.putExtra("content", MainService.newShareEntity.get(position).getTxt());//内容
				intent.putExtra("like", MainService.newShareEntity.get(position).getLike());//赞
				intent.putExtra("reply", MainService.newShareEntity.get(position).getReply());//评论
				intent.putExtra("forward", MainService.newShareEntity.get(position).getForward());//推荐
				intent.putExtra("toId", String.valueOf(MainService.newShareEntity.get(position).getUid())+"");//发表分享者的id
				
				
				List<String> img = new ArrayList<String>();
				List<BlogPic> bpImg = MainService.newShareEntity.get(position).getPicList();
				for(int i=0;i<bpImg.size();i++){
					String pic = bpImg.get(i).getThumb().toString();
					img.add(pic);
				}
				int imgSize = img.size();
				String[] imgArr = (String[]) img.toArray(new String[imgSize]);
				intent.putExtra("imgArr", imgArr);//上传的图片数组
				
				
				if(typeID==1){
					try {
						long data1 =(long)MainService.newShareEntity.get(position).getDateline();
						String originalTime = format.format(data1*1000);
						intent.putExtra("time", originalTime);//原创时间
						intent.putExtra("position",MainService.newShareEntity.get(position).getLocation());//地理位置信息
					} catch (Exception e) {
						intent.putExtra("position","");//地理位置信息
						e.printStackTrace();
					}
				}else{
					long data2 =(long)MainService.newShareEntity.get(position).getModifytime();
					String modifyTime = format.format(data2*1000);
					intent.putExtra("time", modifyTime);//转发时间
					intent.putExtra("title", MainService.newShareEntity.get(position).getTitle());
					intent.putExtra("forwardName", MainService.newShareEntity.get(position).getForwardnickname());
					intent.putExtra("forwardTitle", MainService.newShareEntity.get(position).getForwardtitle());
					intent.putExtra("originalName",MainService.newShareEntity.get(position).getOrigintnickname());
				}
				
				mContext.startActivity(intent);
			}
		});
		
	}

	public class MyListViewAdapter extends BaseAdapter{
//		public TextView recentTv;
		int count = MainService.newShareEntity.size();
		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return count;
		}

		@Override
		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return MainService.newShareEntity.get(position);
		}

		@Override
		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return position;
		}
		
//		public void addPraiseCount(){
//			int totalPrise = likeCount+praiseNum;
//			holder.like_count.setText(String.valueOf(totalPrise));
//			listAdapter.notifyDataSetChanged();
//			listview.postInvalidateDelayed(10);
//		}
//		public void addCommentCount(){
//			int totalComment = commentCount+commentNum;
//			holder.comment_count.setText(String.valueOf(totalComment));
//			listAdapter.notifyDataSetChanged();
//		}
		
		@SuppressLint({ "UseValueOf", "SimpleDateFormat" })
		@Override
		public View getView(final int position, View convertView, ViewGroup parent) {
			
			if (convertView == null) {
				convertView = LayoutInflater.from(mContext).inflate(R.layout.homepage_listview_item_whole, null);
				holder = new ViewHolder();
				
				holder.headImg=(ImageView) convertView.findViewById(R.id.share_photo_item_avatar);
				holder.name=(TextView) convertView.findViewById(R.id.share_photo_item_name);
				holder.time=(TextView) convertView.findViewById(R.id.share_photo_item_time);
				holder.comment_count=(TextView) convertView.findViewById(R.id.share_photo_item_comment_count);
				holder.like_count=(TextView) convertView.findViewById(R.id.share_photo_item_like_count);
				holder.photoItemLayot=(LinearLayout)convertView.findViewById(R.id.share_photo_item_layout);
				holder.comment_count.setTag(position);
				holder.like_count.setTag(position);
				//// typeId = 1 （原创）//////////////////////////////////////////////////////////////////////////////////////
				holder.original = (View) convertView.findViewById(R.id.original_layout);
				holder.original_content_text=(TextView) convertView.findViewById(R.id.share_photo_item_original_content_text);
				holder.original_content_photo1=(ImageView) holder.original.findViewById(R.id.share_photo_item_original_content_photo1);
				holder.original_content_photo2=(ImageView) holder.original.findViewById(R.id.share_photo_item_original_content_photo2);
				holder.original_content_photo3=(ImageView) holder.original.findViewById(R.id.share_photo_item_original_content_photo3);
				holder.original_location = (TextView) holder.original.findViewById(R.id.share_photo_item_from);
				
				//// typeId = 2 （推荐、或、转发、或、分享）//////////////////////////////////////////////////////////////////////////////////////
				holder.transition = (View) convertView.findViewById(R.id.transition_layout);
				holder.forwardTitleLayot=(LinearLayout)holder.transition.findViewById(R.id.forward2_title_layout);
				holder.transition_original_name=(TextView)holder.transition.findViewById(R.id.share_photo_item_transition_original_name);
				holder.transition_title = (TextView) holder.transition.findViewById(R.id.share_photo_item_titie);
				holder.transition_name2= (TextView) holder.transition.findViewById(R.id.share_photo_item_name2);
				holder.transition_title2= (TextView) holder.transition.findViewById(R.id.share_photo_item_title2);
				holder.transition_content_text=(TextView) convertView.findViewById(R.id.share_photo_item_transition_content_text);
				holder.transition_content_photo1=(ImageView) holder.transition.findViewById(R.id.share_photo_item_transition_content_photo1);
				holder.transition_content_photo2=(ImageView) holder.transition.findViewById(R.id.share_photo_item_transition_content_photo2);
				holder.transition_content_photo3=(ImageView) holder.transition.findViewById(R.id.share_photo_item_transition_content_photo3);
				
				convertView.setTag(holder);
			} else {
				holder = (ViewHolder) convertView.getTag();
			}
			
				String headPath=MainService.newShareEntity.get(position).getHeadPic();
//				AsynImageLoader asynImageLoader = new AsynImageLoader();  
//				asynImageLoader.showImageAsyn(holder.headImg, headPath, position);
				
				Bitmap headBit = BitmapLoad.loadBitmap(mContext, headPath);
				holder.headImg.setImageBitmap(headBit);//头像
				holder.name.setText(MainService.newShareEntity.get(position).getNickname());//名字
				
					
					Drawable drawableComment = mContext.getResources().getDrawable(R.drawable.pl0);
					drawableComment.setBounds(0, 0, 58, 35);
					Drawable drawablePraise = mContext.getResources().getDrawable(R.drawable.zan0);
					drawablePraise.setBounds(0, 0, 58, 35);
					
				int commentCount = MainService.newShareEntity.get(position).getReply();
				int likeCount = MainService.newShareEntity.get(position).getLike();
				holder.comment_count.setText(""+commentCount);//评论数量+commentNum
				holder.like_count.setText(""+likeCount);//赞的数量+praiseNum
				
				holder.comment_count.setCompoundDrawables(drawableComment, null, null, null);
				holder.like_count.setCompoundDrawables(drawablePraise, null, null, null);
//				holder.comment_count.setFocusable(false);
//				holder.like_count.setFocusable(false);
				holder.comment_count.setClickable(true);
				holder.like_count.setClickable(true);
				holder.comment_count.setTag(position);
				holder.like_count.setTag(position);
				
			
			picList = new ArrayList<String>();
			blogImg = MainService.newShareEntity.get(position).getPicList();
			for(int i=0;i<blogImg.size();i++){
				String pic = blogImg.get(i).getThumb().toString();
				picList.add(pic);
			}
			int size = picList.size();
			imgPath = (String[])picList.toArray(new String[size]);
			
			
			String txtStr = MainService.newShareEntity.get(position).getTxt().toString().replaceAll("&prime;", "'");//正文内容
			typeID = MainService.newShareEntity.get(position).getTypeId();
			switch (typeID) {
			case 1://默认1：原创
				holder.original.setVisibility(View.VISIBLE);
				holder.transition.setVisibility(View.GONE);
				holder.original_content_text.setText(faceUtil.convertNormalStringToSpannableString(txtStr),BufferType.SPANNABLE);//原创正文内容
				String myLocation = MainService.newShareEntity.get(position).getLocation();
				if("".equals(myLocation)||myLocation==null){
					holder.original_location.setVisibility(View.GONE);
				}else{
					holder.original_location.setText(myLocation);
				}
				try {
					dataTime = (long)MainService.newShareEntity.get(position).getDateline();
					time = format.format(dataTime*1000);
					holder.time.setText(time==""?"":Util.DateCompare(time));//时间
				} catch (ParseException e) {
					holder.time.setText("");
				}
				originalImageView(holder,imgPath,position);
				break;
			case 2://2：推荐  或  分享   或   转发
				holder.original.setVisibility(View.GONE);
				holder.transition.setVisibility(View.VISIBLE);
				holder.transition_title.setText(MainService.newShareEntity.get(position).getTitle());
				if("".equals(MainService.newShareEntity.get(position).getForwardnickname())||
						MainService.newShareEntity.get(position).getForwardnickname()==null){
					holder.forwardTitleLayot.setVisibility(View.GONE);
				}else{
					holder.transition_name2.setText(MainService.newShareEntity.get(position).getForwardnickname());
					holder.transition_title2.setText(MainService.newShareEntity.get(position).getForwardtitle());
				}
				holder.transition_original_name.setVisibility(View.GONE);
				holder.transition_content_text.setText(MainService.newShareEntity.get(position).getOrigintnickname()+":"+
								faceUtil.convertNormalStringToSpannableString(txtStr),BufferType.SPANNABLE);//转发正文内容
				try {
					dataTime = (long)MainService.newShareEntity.get(position).getModifytime();
					time = format.format(dataTime*1000);
					holder.time.setText(time==""?"":Util.DateCompare(time));//时间
				} catch (ParseException e) {
					holder.time.setText("");
				}
				transitionImageView(holder,imgPath,position);
				break;

			default:
				break;
			}
			
			//评论
			holder.comment_count.setEnabled(true);
			holder.comment_count.setOnClickListener(new lvButtonListener(position));
			//赞
			holder.like_count.setEnabled(true);
			holder.like_count.setOnClickListener(new lvButtonListener(position));
			
			return convertView;
		}

		private void originalImageView(ViewHolder holder,String[] imgPath,int position) {
			
			if(imgPath!=null){
				try {
					switch (imgPath.length) {
					case 0:
						holder.original_content_photo1.setVisibility(View.GONE);
						holder.original_content_photo2.setVisibility(View.GONE);
						holder.original_content_photo3.setVisibility(View.GONE);
						break;
					case 1:
//						asynImageLoader.showImageAsyn(holder.original_content_photo1, imgPath[0], position);
						holder.original_content_photo1.setImageBitmap(BitmapLoad.loadBitmap(mContext, imgPath[0]));
						holder.original_content_photo2.setVisibility(View.GONE);
						holder.original_content_photo3.setVisibility(View.GONE);
						break;
					case 2:
//						asynImageLoader.showImageAsyn(holder.original_content_photo1, imgPath[0], position);
//						asynImageLoader.showImageAsyn(holder.original_content_photo2, imgPath[1], position);
						holder.original_content_photo1.setImageBitmap(BitmapLoad.loadBitmap(mContext, imgPath[0]));
						holder.original_content_photo2.setImageBitmap(BitmapLoad.loadBitmap(mContext, imgPath[1]));
						holder.original_content_photo3.setVisibility(View.GONE);
						break;
					default:
//						asynImageLoader.showImageAsyn(holder.original_content_photo1, imgPath[0], position);
//						asynImageLoader.showImageAsyn(holder.original_content_photo2, imgPath[1], position);
//						asynImageLoader.showImageAsyn(holder.original_content_photo3, imgPath[2], position);
						holder.original_content_photo1.setImageBitmap(BitmapLoad.loadBitmap(mContext, imgPath[0]));
						holder.original_content_photo2.setImageBitmap(BitmapLoad.loadBitmap(mContext, imgPath[1]));
						holder.original_content_photo3.setImageBitmap(BitmapLoad.loadBitmap(mContext, imgPath[2]));
						break;
					}
				} catch (Exception e) {
					Util.toast(mContext, "图片加载失败");
					e.printStackTrace();
				}
			}else{
				holder.original_content_photo1.setVisibility(View.GONE);
				holder.original_content_photo2.setVisibility(View.GONE);
				holder.original_content_photo3.setVisibility(View.GONE);
			}
		}
		
		private void transitionImageView(ViewHolder holder,String[] imgPath,int position) {
			
			if(imgPath!=null){
				try {
					switch (imgPath.length) {
					case 0:
						holder.transition_content_photo1.setVisibility(View.GONE);
						holder.transition_content_photo2.setVisibility(View.GONE);
						holder.transition_content_photo3.setVisibility(View.GONE);
						break;
					case 1:
//						asynImageLoader.showImageAsyn(holder.transition_content_photo1, imgPath[0], position);
						
						holder.transition_content_photo1.setImageBitmap(BitmapLoad.loadBitmap(mContext, imgPath[0]));
						holder.transition_content_photo2.setVisibility(View.GONE);
						holder.transition_content_photo3.setVisibility(View.GONE);
						break;
					case 2:
//						asynImageLoader.showImageAsyn(holder.transition_content_photo1, imgPath[0], position);
//						asynImageLoader.showImageAsyn(holder.transition_content_photo2, imgPath[1], position);
						
						holder.transition_content_photo1.setImageBitmap(BitmapLoad.loadBitmap(mContext, imgPath[0]));
						holder.transition_content_photo2.setImageBitmap(BitmapLoad.loadBitmap(mContext, imgPath[1]));
						holder.transition_content_photo3.setVisibility(View.GONE);
						break;
					default:
//						asynImageLoader.showImageAsyn(holder.transition_content_photo1, imgPath[0], position);
//						asynImageLoader.showImageAsyn(holder.transition_content_photo2, imgPath[1], position);
//						asynImageLoader.showImageAsyn(holder.transition_content_photo3, imgPath[2], position);
						
						holder.transition_content_photo1.setImageBitmap(BitmapLoad.loadBitmap(mContext, imgPath[0]));
						holder.transition_content_photo2.setImageBitmap(BitmapLoad.loadBitmap(mContext, imgPath[1]));
						holder.transition_content_photo3.setImageBitmap(BitmapLoad.loadBitmap(mContext, imgPath[2]));
						break;
					}
				} catch (Exception e) {
					Util.toast(mContext, "图片加载失败");
					e.printStackTrace();
				}
			}else{
				holder.transition_content_photo1.setVisibility(View.GONE);
				holder.transition_content_photo2.setVisibility(View.GONE);
				holder.transition_content_photo3.setVisibility(View.GONE);
			}
		}
		
		class lvButtonListener implements OnClickListener{
			
			private int position;
			lvButtonListener(int pos){
				position = pos;
			}
			@Override
			public void onClick(View v) {
				
				// TODO Auto-generated method stub
				if(v.getId()==holder.like_count.getId() && v.getTag().equals(position)){
					holder.like_count.setFocusable(true);
					if(MainService.newShareEntity.get(position).isPraised()==false){
						
						addLikeView = v;
						likePosition = position;
						Communication.addPraise(HSApplication.sp.getString("userid","").toString(), 
								String.valueOf(MainService.newShareEntity.get(position).getUid()), 
								String.valueOf(MainService.newShareEntity.get(position).getId()),
								"item05","");
						
						
					}else{
						Util.toast(mContext, "您已经赞过了");
					}
						
				}
				else if(v.getId()==holder.comment_count.getId() && v.getTag().equals(position)){
					holder.comment_count.setFocusable(true);
					bottomLayout1.setVisibility(View.GONE);
					bottomLayout2.setVisibility(View.VISIBLE);
					
					addCommentView = v;
					
					String commentCountStr = ((TextView) v).getText().toString();
					addCommentCount = Integer.valueOf(commentCountStr);
					addCommentCount++;
					
					
					toUserId=String.valueOf(MainService.newShareEntity.get(position).getUid());//发表微博的用户id
					toBlogId=String.valueOf(MainService.newShareEntity.get(position).getId());//微博id
				
				}
				
			}
			
		}

		class ViewHolder {
			//不变的
			ImageView headImg;//头像
			TextView name;//名字
			TextView time;//时间
			TextView comment_count;//评论数量
			TextView like_count;//赞数量
			
			View original;//原创的
//			TextView original_title;
			TextView original_all;
			TextView original_location;
			TextView original_content_text;//正文内容
			ImageView original_content_photo1;//图片1
			ImageView original_content_photo2;//图片2
			ImageView original_content_photo3;//图片3

			
			View transition;//转发的
			LinearLayout photoItemLayot;
			LinearLayout forwardTitleLayot;//二级推荐布局
			TextView transition_original_name;//原创者姓名
			TextView transition_title;
			TextView transition_name2;
			TextView transition_title2;
			TextView transition_content_text;//正文内容
			ImageView transition_content_photo1;//图片1
			ImageView transition_content_photo2;//图片2
			ImageView transition_content_photo3;//图片3
		}

	}

	@Override
	public void onRefresh() {
		// TODO Auto-generated method stub
		new Thread(new Runnable() {
			 
            @Override
            public void run() {
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                Communication.getNewShare(listCount,"fresh");//请求数据
            }
        }).start();
	}


	@Override
	public void onMore() {
		// TODO Auto-generated method stub
		new Thread(new Runnable() {
			 
            @Override
            public void run() {
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                listCount+=8;
				Communication.getNewShareMore(listCount);
				
            }
        }).start();
	}

	
	
}
